package dialog.dialogs;


import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class CustomMessageDialog extends Dialog 
{
	private static final int RESET_ID = IDialogConstants.NO_TO_ALL_ID + 1;

	private Text nameField = null;
	private Text passField = null;
	
	private String nameData = "";
	private String passwordData = "";
	
	
	
	public String getNameData() 
	{
		return nameData;
	}


	public String getPasswordData() 
	{
		return passwordData;
	}


	public CustomMessageDialog(Shell parent) 
	{
		super(parent);
	}


	@Override
	protected Control createDialogArea(Composite parent) 
	{
		Composite composite = null;
		
		GridLayout layout = null;
		GridData griddata = null;
		
		Label nameLabel = null;
		Label passLabel = null;
		
		
		
		
		try 
		{
			composite = (Composite) super.createDialogArea(parent);
			
			layout = (GridLayout) composite.getLayout();
			layout.numColumns = 2;
			
			griddata = new GridData(GridData.FILL_HORIZONTAL);
			
			nameLabel = new Label(composite, SWT.RIGHT);
			nameLabel.setText("UserName : ");
			
			this.nameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
			this.nameField.setLayoutData(griddata);
			
			passLabel = new Label(composite, SWT.RIGHT);
			passLabel.setText("Password  : ");
			
			this.passField = new Text(composite, SWT.SINGLE | SWT.PASSWORD | SWT.BORDER);
			this.passField.setLayoutData(griddata);
			
			
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}

		
		
		
		return composite;
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) 
	{
		super.createButtonsForButtonBar(parent);
		this.createButton(parent, RESET_ID, "Reset All" , false);
		
	}
	
	@Override
	protected void buttonPressed(int buttonId) 
	{
		if(buttonId == RESET_ID)
		{
			this.nameField.setText("");
			this.passField.setText("");
		}
		else if(buttonId == IDialogConstants.OK_ID)
		{
			this.nameData = this.nameField.getText();
			this.passwordData = this.passField.getText();
			
			super.buttonPressed(buttonId);
		}
		else
		{
			super.buttonPressed(buttonId);
		}
		
		
	}
	
}// public class
